﻿using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp1.TongShiWei.segmentationData
{
    public partial class PackageData : UIForm
    {
        //定义委托
        public event Action<List<string>, string> GetPackageData_;
        public PackageData()
        {
            InitializeComponent();
            #region 添加计算器点击事件
            //OnGetNumButtons += uiButton5_Click;
            //OnGetNumButtons += uiButton13_Click;
            //OnGetNumButtons += uiButton10_Click;
            //OnGetNumButtons += uiButton15_Click;
            //OnGetNumButtons += uiButton12_Click;
            //OnGetNumButtons += uiButton9_Click;
            //OnGetNumButtons += uiButton14_Click;
            //OnGetNumButtons += uiButton11_Click;
            //OnGetNumButtons += uiButton17_Click;
            //OnGetNumButtons += uiButton8_Click;
            //OnGetNumButtons += uiButton7_Click;
            //OnGetNumButtons += uiButton6_Click;
            #endregion
            #region 计算总数量和总重量
            this.Znum.Text = (Convert.ToDouble(this.yellowZnum.Text) + Convert.ToDouble(this.RedZnum.Text) + Convert.ToDouble(this.GreenZnum.Text) + Convert.ToDouble(this.BlueZnum.Text)).ToString();
            this.Zkg.Text = (Convert.ToDouble(this.Znum.Text) * 0.5).ToString();
            #endregion
        }
        //包装分类
        string PackageTypeName = null;

        #region 计算机的操作
        // 计算机的加减
        public void GetPackageZnumandZkg(object Znum)
        {
            if (PackageTypeName != null)
            {
                switch (PackageTypeName)
                {
                    case "黄包装":
                        this.yellowZnum.Text = this.yellowZnum.Text == "0" ? "" : this.yellowZnum.Text;
                        this.yellowZnum.Text = this.yellowZnum.Text + Znum.ToString();
                        this.YellowZkg.Text = (Convert.ToDouble(this.yellowZnum.Text) * 0.5).ToString();
                        break;
                    case "红包装":
                        this.RedZnum.Text = this.RedZnum.Text == "0" ? "" : this.RedZnum.Text;
                        this.RedZnum.Text = this.RedZnum.Text + Znum.ToString();
                        this.RedZkg.Text = (Convert.ToDouble(this.RedZnum.Text) * 0.5).ToString();
                        break;
                    case "绿包装":
                        this.GreenZnum.Text = this.GreenZnum.Text == "0" ? "" : this.GreenZnum.Text;
                        this.GreenZnum.Text = this.GreenZnum.Text + Znum.ToString();
                        this.GreenZkg.Text = (Convert.ToDouble(this.GreenZnum.Text) * 0.5).ToString();
                        break;
                    case "蓝包装":
                        this.BlueZnum.Text = this.BlueZnum.Text == "0" ? "" : this.BlueZnum.Text;
                        this.BlueZnum.Text = this.BlueZnum.Text + Znum.ToString();
                        this.BlueZkg.Text = (Convert.ToDouble(this.BlueZnum.Text) * 0.5).ToString();
                        break;
                    default:
                        break;
                }
                this.Znum.Text = (Convert.ToDouble(this.yellowZnum.Text) + Convert.ToDouble(this.RedZnum.Text) + Convert.ToDouble(this.GreenZnum.Text) + Convert.ToDouble(this.BlueZnum.Text)).ToString();
                this.Zkg.Text = (Convert.ToDouble(this.Znum.Text) * 0.5).ToString();
            }
        }
        // 计算机的退格和清空
        public void ClearPackageData(string? ClearTypeData)
        {
            if (PackageTypeName != null)
            {
                switch (PackageTypeName)
                {
                    case "黄包装":
                        if (ClearTypeData == "退格")
                        {
                            this.yellowZnum.Text = this.yellowZnum.Text.Substring(0, this.yellowZnum.Text.Length - 1);
                            this.YellowZkg.Text = (Convert.ToDouble(this.yellowZnum.Text) * 0.5).ToString();
                        }
                        else if (ClearTypeData == "清空")
                        {
                            this.yellowZnum.Text = "0";
                            this.YellowZkg.Text = "0";
                        }
                        break;
                    case "红包装":
                        if (ClearTypeData == "退格")
                        {
                            this.RedZnum.Text = this.RedZnum.Text.Substring(0, this.RedZnum.Text.Length - 1);
                            this.RedZkg.Text = (Convert.ToDouble(this.RedZnum.Text) * 0.5).ToString();
                        }
                        else if (ClearTypeData == "清空")
                        {
                            this.RedZnum.Text = "0";
                            this.RedZkg.Text = "0";
                        }
                        break;
                    case "绿包装":
                        if (ClearTypeData == "退格")
                        {
                            this.GreenZnum.Text = this.GreenZnum.Text.Substring(0, this.GreenZnum.Text.Length - 1);
                            this.GreenZkg.Text = (Convert.ToDouble(this.GreenZnum.Text) * 0.5).ToString();
                        }
                        else if (ClearTypeData == "清空")
                        {
                            this.GreenZnum.Text = "0";
                            this.GreenZkg.Text = "0";
                        }
                        break;
                    case "蓝包装":
                        if (ClearTypeData == "退格")
                        {
                            this.BlueZnum.Text = this.BlueZnum.Text.Substring(0, this.BlueZnum.Text.Length - 1);
                            this.BlueZkg.Text = (Convert.ToDouble(this.BlueZnum.Text) * 0.5).ToString();
                        }
                        else if (ClearTypeData == "清空")
                        {
                            this.BlueZnum.Text = "0";
                            this.BlueZkg.Text = "0";
                        }
                        break;
                    default:
                        break;
                }
                this.Znum.Text = (Convert.ToDouble(this.yellowZnum.Text) + Convert.ToDouble(this.RedZnum.Text) + Convert.ToDouble(this.GreenZnum.Text) + Convert.ToDouble(this.BlueZnum.Text)).ToString();
                this.Zkg.Text = (Convert.ToDouble(this.Znum.Text) * 0.5).ToString();
            }
        }
        #endregion
        
        #region 计算器点击事件
        //1
        private async void uiButton5_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(1);
        }
        //2
        private void uiButton13_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(2);
        }
        //3

        private void uiButton10_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(3);
        }
        //4
        private void uiButton15_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(4);
        }
        //5
        private void uiButton12_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(5);
        }
        //6
        private void uiButton9_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(6);
        }
        //7
        private void uiButton14_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(7);
        }
        //8
        private void uiButton11_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(8);
        }
        //9
        private void uiButton17_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(9);
        }
        //0
        private void uiButton8_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(0);
        }
        //.
        private void uiButton7_Click(object sender, EventArgs e)
        {
            GetPackageZnumandZkg(".");
        }
        //退格
        private void uiButton6_Click(object sender, EventArgs e)
        {
            ClearPackageData("退格");
        }
        //清空

        private void uiButton20_Click(object sender, EventArgs e)
        {
            ClearPackageData("清空");
        }
        //关闭
        private void uiButton19_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //确定
        private void uiButton18_Click(object sender, EventArgs e)
        {
            List<string> PackageDatas = new List<string>();
            #region 获取包装数据
            //黄包装
            if (Convert.ToInt32(this.yellowZnum.Text) >0)
            {
                string PackageDataName = this.yellowButton.Text;
                string PackageDataZnum = this.yellowZnum.Text;
                string PackageDataZkg = this.YellowZkg.Text;
                string PackageData = "包装:" + PackageDataName + "数量:" + PackageDataZnum + "重量:" + PackageDataZkg;
                PackageDatas.Add(PackageData);
            }
            //红包装
            if (Convert.ToInt32(this.RedZnum.Text) > 0)
            {
                string PackageDataName = this.redButton.Text;
                string PackageDataZnum = this.RedZnum.Text;
                string PackageDataZkg = this.RedZkg.Text;
                string PackageData = "包装:" + PackageDataName + "数量:" + PackageDataZnum + "重量:" + PackageDataZkg;
                PackageDatas.Add(PackageData);
            }
            //绿包装
            if (Convert.ToInt32(this.GreenZnum.Text) >0)
            {
                string PackageDataName = this.greenButton.Text;
                string PackageDataZnum = this.GreenZnum.Text;
                string PackageDataZkg = this.GreenZkg.Text;
                string PackageData = "包装:" + PackageDataName + "数量:" + PackageDataZnum + "重量:" + PackageDataZkg;
                PackageDatas.Add(PackageData);
            }
            //蓝包装
            if (Convert.ToInt32(this.BlueZnum.Text) >0)
            {
                string PackageDataName = this.blueButton.Text;
                string PackageDataZnum = this.BlueZnum.Text;
                string PackageDataZkg = this.BlueZkg.Text;
                string PackageData = "包装:" + PackageDataName + "数量:" + PackageDataZnum + "重量:" + PackageDataZkg;
                PackageDatas.Add(PackageData);
            }
            #endregion
            GetPackageData_?.Invoke(PackageDatas,this.Zkg.Text);
            this.Close();
        }
        #endregion

        #region 包装选择
        //黄包装
        private void uiButton1_Click(object sender, EventArgs e)
        {
            this.yellowButton.FillColor = Color.DodgerBlue;
            this.redButton.FillColor = Color.White;
            this.greenButton.FillColor = Color.White;
            this.blueButton.FillColor = Color.White;
            PackageTypeName = "黄包装";
        }
        //红包装
        private void uiButton4_Click(object sender, EventArgs e)
        {
            this.yellowButton.FillColor = Color.White;
            this.redButton.FillColor = Color.DodgerBlue;
            this.greenButton.FillColor = Color.White;
            this.blueButton.FillColor = Color.White;
            PackageTypeName = "红包装";
        }
        //绿包装
        private void uiButton3_Click(object sender, EventArgs e)
        {
            this.yellowButton.FillColor = Color.White;
            this.redButton.FillColor = Color.White;
            this.greenButton.FillColor = Color.DodgerBlue;
            this.blueButton.FillColor = Color.White;
            PackageTypeName = "绿包装";
        }
        //蓝包装
        private void uiButton2_Click(object sender, EventArgs e)
        {
            this.yellowButton.FillColor = Color.White;
            this.redButton.FillColor = Color.White;
            this.greenButton.FillColor = Color.White;
            this.blueButton.FillColor = Color.DodgerBlue;
            PackageTypeName = "蓝包装";
        }
        #endregion

    }
}
